require "gruff"
require File.dirname(__FILE__)+"/../../lib/gchartrb/google_chart"

module StatusHelper
  
  
  
    
  def create_bar_chart 
    
    lc = GoogleChart::BarChart.new('320x200', "Score Bars", false)
    lc.data_encoding = :score
    
    lc.show_legend = true 
    lc.show_labels = false
    
    i=0
    @current_scores.each do |player_name, score|
        lc.data player_name.to_s, score.to_a, colors[i]
      i += 1      
    end
    
    lc.to_url
  end
  
  def colors
    ["0000ff", "00ff00", "ff0000", "ff9900", "00ffff", "0ffff0", "000000","9900FF","0099FF"]
  end
  
  def create_trend_url 
    
    lc = GoogleChart::LineChart.new('500x600', "Progress Worms", false)
    lc.data_encoding = :score
    
    lc.show_legend = true 
    lc.show_labels = false
    
    lc.fill(:chart, :solid, {:color => 'eeeeee'})
    
    update_max()
    lc.max_value = @max
    
    i=0
    @historical_scores.each do |player_name, scores|
#      scores_for_graph = scores.map{|score| score/@max.to_f}
      p "player=#{player_name.to_s}; scores = #{scores.last(3).inspect}"
#      p "player=#{player_name.to_s}; scores_for_graph = #{scores_for_graph.last(3).inspect}"
      lc.data player_name.to_s, scores.last(10), colors[i]
      i += 1
      p "color = #{i}"
    end
    
    lc.to_url
  end
  
  def update_max
    if (@current_scores.values.flatten.max > @max)
      @max = @current_scores.values.flatten.max
    end
  end
  
  def test_gchart
    lc = GoogleChart::LineChart.new('320x200', "Line Chart", false)
    lc.data "Trend 1", [0.5,0.4,0.3,0.1,0.3,0.5,0.6], '0000ff'
    lc.show_legend = true 
    lc.show_labels = false
    lc.data "Trend 2", [0.1,0.2,0.3,0.4,0.5,0.6], '00ff00'
    lc.to_url
  end
end
